/*FCApr9JgjfAoCk3vK7TNA1GBRuxwPW9T6oFZzBLbXgYK/8hTm6zSQs/pP8oAbJDG*/
import { assetAppcode, assetTransferPageCode, assetTransferSearch, assetTransferHead } from '../constants';
import { linkCard } from './buttonClick';

import ampub from 'ampub';
import fa from 'fa';

const { commonConst } = ampub;
const { CommonKeys } = commonConst;
const { IBusiRoleConst } = CommonKeys;

const { fa_components } = fa;
const { addSearchAreaReferFilter } = fa_components.ReferFilter;

export default function(props) {
	props.createUIDom(
		{
			pagecode: assetTransferPageCode,
			appcode: assetAppcode
		},
		(data) => {
			if (data) {
				if (data.template) {
					let meta = data.template;
					meta = modifierMeta.call(this, props, meta);
					props.meta.addMeta(meta);
				}
			}
		}
	);
}
function modifierMeta(props, meta) {
	let ListConfig = {
		searchId: assetTransferSearch,
		specialFields: {
			pk_applyorg: {
				// 申请单位
				data: [
					{
						fields: [ 'pk_org' ],
						returnName: 'pk_org'
					}
				]
			},
			pk_applydapt: {
				orgMulti: 'pk_org',
				// 申请部门
				data: [
					{
						fields: [ 'pk_applyorg', 'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			},

			pk_proposer: {
				// 申请人
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_applyorg' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}

				]
			},
			pk_transactor: {
				// 经办人
				orgMulti: 'pk_org',
				data: [
					{
						fields: [ 'pk_org' ],
						returnName: 'pk_org'
					},
					{
						returnConst: IBusiRoleConst.ASSETORG,
						returnName: 'busifuncode'
					}
				]
			}
		}
	};
	// 查询条件过滤
	addSearchAreaReferFilter.call(this, props, meta, ListConfig);

	//增加超链接
	meta[assetTransferHead].items = meta[assetTransferHead].items.map((item, key) => {
		if (item.attrcode == 'bill_code') {
			item.render = (text, record, index) => {
				let transType = record.transi_type.value;
				return (
					<div class="simple-table-td">
						<span
							className="code-detail-link"
							onClick={() => {
								linkCard.call(this, props, record, 'pk_newasset', transType);
							}}
						>
							{record && record.bill_code && record.bill_code.value}
						</span>
					</div>
				);
			};
		}

		return item;
	});
	return meta;
}

/*FCApr9JgjfAoCk3vK7TNA1GBRuxwPW9T6oFZzBLbXgYK/8hTm6zSQs/pP8oAbJDG*/